package com.swallow.auth.common.result;

import com.swallow.auth.common.enums.ErrorCode;

/**
 * @author: 18310740596@163.com
 * @date: 2024-05-10 23:38:13
 * @version: v1.0
 * @describe: 错误静态类
 */
public class R {

    public static <T> Result<T> success() {
        return success(ErrorCode.SUCCESS.getValue(), ErrorCode.SUCCESS.getName(), null);
    }

    public static <T> Result<T> success(String message, T data) {
        return success(ErrorCode.SUCCESS.getValue(), message, data);
    }

    public static <T> Result<T> success(T data) {
        return success(ErrorCode.SUCCESS.getValue(), ErrorCode.SUCCESS.getName(), data);
    }

    private static <T> Result<T> success(String code, String message, T data) {
        return create(code, message, data);
    }

    private static <T> Result<T> create(String code, String message, T data) {
        return new Result<>(code, message, data);
    }


    public static <T> Result<T> error() {
        return create(ErrorCode.SYSTEM_ERROR.getValue(), ErrorCode.SYSTEM_ERROR.getName(), null);
    }

    public static <T> Result<T> error(String message) {
        return create(ErrorCode.SYSTEM_ERROR.getValue(), message, null);
    }

    public static <T> Result<T> error(String code, String message) {
        return create(code, message, null);
    }

    public static <T> Result<T> error(String code, String message, T data) {
        return create(code, message, data);
    }
}
